<!-- HTML header for doxygen 1.8.13-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>MTB CAT1 Peripheral driver library: Initialization and Basic Functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><a href="http://www.cypress.com/"><img alt="Logo" src="IFXCYP_one-line.png"/></a></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">MTB CAT1 Peripheral driver library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__group__sar__functions__basic.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Initialization and Basic Functions<div class="ingroups"><a class="el" href="group__group__sar.html">SAR          (SAR ADC Subsystem)</a> &raquo; <a class="el" href="group__group__sar__functions.html">Functions</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">General Description</h2>
<p>This set of functions is for initialization and basic usage. </p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga5c053a77ca29519ca29da56da7eaeebe"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#ga5c053a77ca29519ca29da56da7eaeebe">Cy_SAR_Init</a> (<a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, const <a class="el" href="structcy__stc__sar__config__t.html">cy_stc_sar_config_t</a> *config)</td></tr>
<tr class="memdesc:ga5c053a77ca29519ca29da56da7eaeebe"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize all SAR configuration registers.  <a href="#ga5c053a77ca29519ca29da56da7eaeebe">More...</a><br /></td></tr>
<tr class="separator:ga5c053a77ca29519ca29da56da7eaeebe"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga65876b1a551f1d189b4abcdb24ff82fa"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#ga65876b1a551f1d189b4abcdb24ff82fa">Cy_SAR_DeInit</a> (<a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, bool deInitRouting)</td></tr>
<tr class="memdesc:ga65876b1a551f1d189b4abcdb24ff82fa"><td class="mdescLeft">&#160;</td><td class="mdescRight">Reset SAR registers back to power on reset defaults.  <a href="#ga65876b1a551f1d189b4abcdb24ff82fa">More...</a><br /></td></tr>
<tr class="separator:ga65876b1a551f1d189b4abcdb24ff82fa"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga4b8bb939483fac5768910156075d4264"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#ga4b8bb939483fac5768910156075d4264">Cy_SAR_Enable</a> (<a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base)</td></tr>
<tr class="memdesc:ga4b8bb939483fac5768910156075d4264"><td class="mdescLeft">&#160;</td><td class="mdescRight">Power up the SAR ADC subsystem block.  <a href="#ga4b8bb939483fac5768910156075d4264">More...</a><br /></td></tr>
<tr class="separator:ga4b8bb939483fac5768910156075d4264"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga09f2185e586c580e622a252580793a25"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#ga09f2185e586c580e622a252580793a25">Cy_SAR_Disable</a> (<a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base)</td></tr>
<tr class="memdesc:ga09f2185e586c580e622a252580793a25"><td class="mdescLeft">&#160;</td><td class="mdescRight">Turn off the hardware block.  <a href="#ga09f2185e586c580e622a252580793a25">More...</a><br /></td></tr>
<tr class="separator:ga09f2185e586c580e622a252580793a25"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga92cb7f3c5947df6e47b59f1b2796883c"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#ga92cb7f3c5947df6e47b59f1b2796883c">Cy_SAR_StartConvert</a> (<a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, <a class="el" href="group__group__sar__enums.html#gaf21d08e4f15f54ac638943e50538d95c">cy_en_sar_start_convert_sel_t</a> startSelect)</td></tr>
<tr class="memdesc:ga92cb7f3c5947df6e47b59f1b2796883c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Start a single scan (one shot) of all enabled channels or start scanning continuously.  <a href="#ga92cb7f3c5947df6e47b59f1b2796883c">More...</a><br /></td></tr>
<tr class="separator:ga92cb7f3c5947df6e47b59f1b2796883c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga1397031ccf2c1f8a5a95a77f9362e1d1"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#ga1397031ccf2c1f8a5a95a77f9362e1d1">Cy_SAR_StopConvert</a> (<a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base)</td></tr>
<tr class="memdesc:ga1397031ccf2c1f8a5a95a77f9362e1d1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Stop continuous scanning of enabled channels.  <a href="#ga1397031ccf2c1f8a5a95a77f9362e1d1">More...</a><br /></td></tr>
<tr class="separator:ga1397031ccf2c1f8a5a95a77f9362e1d1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga977c6fb6f81ee39d27eae43c0e45d85c"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#ga977c6fb6f81ee39d27eae43c0e45d85c">Cy_SAR_IsEndConversion</a> (<a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, <a class="el" href="group__group__sar__enums.html#ga31da850b49ff727a00789aaa33104c59">cy_en_sar_return_mode_t</a> retMode)</td></tr>
<tr class="memdesc:ga977c6fb6f81ee39d27eae43c0e45d85c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Immediately return the status of the conversion or does not return (blocking) until the conversion completes, depending on the retMode parameter.  <a href="#ga977c6fb6f81ee39d27eae43c0e45d85c">More...</a><br /></td></tr>
<tr class="separator:ga977c6fb6f81ee39d27eae43c0e45d85c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga5d7a3489629382b1e46477c034bbb2d0"><td class="memItemLeft" align="right" valign="top">int16_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a> (const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, uint32_t chan)</td></tr>
<tr class="memdesc:ga5d7a3489629382b1e46477c034bbb2d0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return the data available in the channel result data register as a signed 16-bit integer.  <a href="#ga5d7a3489629382b1e46477c034bbb2d0">More...</a><br /></td></tr>
<tr class="separator:ga5d7a3489629382b1e46477c034bbb2d0"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gafe907896ffee98cc780042ad77fe71cc"><td class="memItemLeft" align="right" valign="top">int32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#gafe907896ffee98cc780042ad77fe71cc">Cy_SAR_GetResult32</a> (const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, uint32_t chan)</td></tr>
<tr class="memdesc:gafe907896ffee98cc780042ad77fe71cc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return the data available in the channel result data register as a signed 32-bit integer.  <a href="#gafe907896ffee98cc780042ad77fe71cc">More...</a><br /></td></tr>
<tr class="separator:gafe907896ffee98cc780042ad77fe71cc"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga859687d40491a053c7fd8d489244f2ac"><td class="memItemLeft" align="right" valign="top">__STATIC_INLINE uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#ga859687d40491a053c7fd8d489244f2ac">Cy_SAR_GetChanResultUpdated</a> (const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base)</td></tr>
<tr class="memdesc:ga859687d40491a053c7fd8d489244f2ac"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return whether the RESULT register has been updated or not.  <a href="#ga859687d40491a053c7fd8d489244f2ac">More...</a><br /></td></tr>
<tr class="separator:ga859687d40491a053c7fd8d489244f2ac"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga397abcd1a595c0846971769a8fe2d564"><td class="memItemLeft" align="right" valign="top">__STATIC_INLINE void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__group__sar__functions__basic.html#ga397abcd1a595c0846971769a8fe2d564">Cy_SAR_EnableInjection</a> (<a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *base, bool tailgating)</td></tr>
<tr class="memdesc:ga397abcd1a595c0846971769a8fe2d564"><td class="mdescLeft">&#160;</td><td class="mdescRight">Triggers the injection channel sample.  <a href="#ga397abcd1a595c0846971769a8fe2d564">More...</a><br /></td></tr>
<tr class="separator:ga397abcd1a595c0846971769a8fe2d564"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga5c053a77ca29519ca29da56da7eaeebe"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5c053a77ca29519ca29da56da7eaeebe">&#9670;&nbsp;</a></span>Cy_SAR_Init()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a> Cy_SAR_Init </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structcy__stc__sar__config__t.html">cy_stc_sar_config_t</a> *&#160;</td>
          <td class="paramname"><em>config</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialize all SAR configuration registers. </p>
<p>If routing is to be configured, all switches will be cleared before being initialized.</p>
<dl class="section note"><dt>Note</dt><dd>If interleaved averaging mode is used, the Differential Result Format should be the same as the Single-Ended Result Format. Otherwise, this function will return CY_SAR_BAD_PARAM.</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing SAR instance registers</td></tr>
    <tr><td class="paramname">config</td><td>Pointer to structure containing configuration data. See <a class="el" href="structcy__stc__sar__config__t.html">cy_stc_sar_config_t</a> and guidance in the <a class="el" href="group__group__sar.html#group_sar_initialization">Initialization and Enable</a> section.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><ul>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a1bcc04151b677cb6e16050b40309b21a">CY_SAR_SUCCESS</a> : initialization complete successfully</li>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a57b9a5eff2273406f83163b1327d90a3">CY_SAR_BAD_PARAM</a> : input pointers are null or some configuration setting is invalid, initialization incomplete.</li>
</ul>
</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd><div class="fragment"><div class="line">    </div><div class="line">    <span class="comment">/* Scenario: Configure the SAR to sample two channels with a scan rate of 50 ksps.</span></div><div class="line"><span class="comment">     *  - Channel 0 is a single ended channel on P10.2</span></div><div class="line"><span class="comment">     *  - Channel 1 is a differential channel between P10.0 and P10.1.</span></div><div class="line"><span class="comment">    */</span></div><div class="line"><span class="preprocessor">    #define CHANNEL_EN          3u  </span><span class="comment">/* Enable channels 0 and 1. */</span><span class="preprocessor"></span></div><div class="line">       </div><div class="line"><span class="preprocessor">    #define CHANNEL_0_CONFIG    CY_SAR_CHAN_SINGLE_ENDED        </span><span class="comment">/* Channel 0 is a single ended channel. */</span><span class="preprocessor"> \</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_CHAN_SAMPLE_TIME_0     </span><span class="comment">/* Aperature time is set by Sample Time 0. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_POS_PORT_ADDR_SARMUX   </span><span class="comment">/* Use the SARMUX dedicated port (see the device datasheet for the SARMUX port). */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_CHAN_POS_PIN_ADDR_2    </span><span class="comment">/* Use Pin 2 of the SARMUX. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_CHAN_AVG_DISABLE       </span><span class="comment">/* Disable averaging. */</span><span class="preprocessor"></span></div><div class="line">    </div><div class="line"><span class="preprocessor">    #define CHANNEL_1_CONFIG    CY_SAR_CHAN_DIFFERENTIAL_PAIRED </span><span class="comment">/* Channel 1 is a differential paired channel. */</span><span class="preprocessor"> \</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_CHAN_SAMPLE_TIME_1     </span><span class="comment">/* Aperature time is set by Sample Time 1. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_POS_PORT_ADDR_SARMUX   </span><span class="comment">/* Use the SARMUX dedicated port (see the device datasheet for the SARMUX port). */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_CHAN_POS_PIN_ADDR_0    </span><span class="comment">/* Positive terminal is connected to Pin 0 and negative terminal is connected to Pin 1 of the SARMUX. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_CHAN_AVG_ENABLE        </span><span class="comment">/* Enable averaging. */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define CHANNEL_CONFIG      {(uint32_t)CHANNEL_0_CONFIG, \</span></div><div class="line"><span class="preprocessor">                                 (uint32_t)CHANNEL_1_CONFIG, \</span></div><div class="line"><span class="preprocessor">                                 0U,0U,0U,0U,0U,0U,0U,0U,0U,0U,0U,0U,0U,0U} </span><span class="comment">/* All other channels are unconfigured. */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define CTRL                  (uint32_t)CY_SAR_VREF_PWR_100           </span><span class="comment">/* Set reference voltage buffer to full power (100%) */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_VREF_SEL_VDDA_DIV_2    </span><span class="comment">/* Select internal VDDA/2 as the Vref. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_BYPASS_CAP_ENABLE      </span><span class="comment">/* Enable Vref bypass capacitory. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_NEG_SEL_VREF           </span><span class="comment">/* Use Vref as the negative terminal for all single-ended channels. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_CTRL_NEGVREF_HW        </span><span class="comment">/* Enable hardware control of switch between Vref and negative terminal. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_CTRL_COMP_DLY_2P5      </span><span class="comment">/* Set comparator latch delay to 2.5 ns delay for maximum conversion rates. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_COMP_PWR_100           </span><span class="comment">/* Set comparator power to full power for maximum conversion rates. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_DEEPSLEEP_SARMUX_OFF   </span><span class="comment">/* Disable SARMUX in Deep Sleep mode. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_SARSEQ_SWITCH_ENABLE   </span><span class="comment">/* Enable the SARSEQ. */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define SAMPLE_CTRL           (uint32_t)CY_SAR_RIGHT_ALIGN                </span><span class="comment">/* Right align result data to bits[11:0]. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_SINGLE_ENDED_UNSIGNED      </span><span class="comment">/* Single ended channels are unsigned. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_DIFFERENTIAL_SIGNED        </span><span class="comment">/* Differential channels are signed. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_AVG_CNT_2                  </span><span class="comment">/* Set number of samples averaged to 2. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_AVG_MODE_SEQUENTIAL_FIXED  </span><span class="comment">/* Averaging mode is sequential 12-bit fixed.*/</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (uint32_t)CY_SAR_TRIGGER_MODE_FW_ONLY       </span><span class="comment">/* Hardware trigger is disabled. */</span><span class="preprocessor"></span></div><div class="line">    </div><div class="line"><span class="preprocessor">    #define SAMPLE_TIME01       (135 &lt;&lt; CY_SAR_SAMPLE_TIME0_SHIFT)  </span><span class="comment">/* Sample Time 0 set to 134 ADC clock cycles. */</span><span class="preprocessor"> \</span></div><div class="line"><span class="preprocessor">                                | (4 &lt;&lt; CY_SAR_SAMPLE_TIME1_SHIFT)  </span><span class="comment">/* Sample Time 1 set to 3 ADC clock cycles. */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line">    <span class="comment">/* Note, sample times 2 and 3 are not used by any channels in this example. */</span></div><div class="line"><span class="preprocessor">    #define SAMPLE_TIME23       (4 &lt;&lt; CY_SAR_SAMPLE_TIME2_SHIFT)    </span><span class="comment">/* Sample Time 2 set to 3 ADC clock cycles. */</span><span class="preprocessor"> \</span></div><div class="line"><span class="preprocessor">                                | (4 &lt;&lt; CY_SAR_SAMPLE_TIME3_SHIFT)  </span><span class="comment">/* Sample Time 3 set to 3 ADC clock cycles. */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define RANGE_THRES         (0x300uL  &lt;&lt; CY_SAR_RANGE_LOW_SHIFT)     </span><span class="comment">/* Lower limit of range detection is 0x300. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | (0xC00uL  &lt;&lt; CY_SAR_RANGE_HIGH_SHIFT) </span><span class="comment">/* Upper limit of range detection is 0xC00. */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define INTR_MASK           CY_SAR_INTR_EOS | CY_SAR_INTR_OVERFLOW </span><span class="comment">/* Enable both EOS and overflow interrupt events. */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define MUX_SWITCH          CY_SAR_MUX_FW_P2_VPLUS          </span><span class="comment">/* Connect Pin 2 of the SARMUX to the positive terminal of the SARADC. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_MUX_FW_P0_VPLUS        </span><span class="comment">/* Connect Pin 0 of the SARMUX to the positive terminal of the SARADC. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_MUX_FW_P1_VMINUS       </span><span class="comment">/* Connect Pin 1 of the SARMUX to the negative terminal of the SARADC. */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line"><span class="preprocessor">    #define MUX_SWITCH_SQ_CTRL  CY_SAR_MUX_SQ_CTRL_P0           </span><span class="comment">/* Enable sequencer control of Pins 0 of the SARMUX. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_MUX_SQ_CTRL_P1         </span><span class="comment">/* Enable sequencer control of Pins 1 of the SARMUX. */</span><span class="preprocessor">\</span></div><div class="line"><span class="preprocessor">                                | CY_SAR_MUX_SQ_CTRL_P2         </span><span class="comment">/* Enable sequencer control of Pins 2 of the SARMUX. */</span><span class="preprocessor"></span></div><div class="line"></div><div class="line">    <span class="comment">/* Define the config structure. */</span></div><div class="line">    <span class="keyword">const</span> <a class="code" href="structcy__stc__sar__config__t.html">cy_stc_sar_config_t</a> config =</div><div class="line">    {</div><div class="line">        <span class="comment">/* .ctrl               */</span>   (uint32_t)CTRL,</div><div class="line">        <span class="comment">/* .sampleCtrl         */</span>   (uint32_t)SAMPLE_CTRL,</div><div class="line">        <span class="comment">/* .sampleTime01       */</span>   SAMPLE_TIME01,</div><div class="line">        <span class="comment">/* .sampleTime23       */</span>   SAMPLE_TIME23,</div><div class="line">        <span class="comment">/* .rangeThres         */</span>   RANGE_THRES,</div><div class="line">        <span class="comment">/* .limitCond          */</span>   <a class="code" href="group__group__sar__range__thres__register__enums.html#ggaccf649d65a86e17939c3d20a684cd9cda05ef1644deb92e634e163532a3b2179e">CY_SAR_RANGE_COND_OUTSIDE</a>,      <span class="comment">/* Set limit condition to outside of lower and upper limits. */</span></div><div class="line">        <span class="comment">/* .chanEn             */</span>   CHANNEL_EN,</div><div class="line">        <span class="comment">/* .chanConfig         */</span>   CHANNEL_CONFIG,</div><div class="line">        <span class="comment">/* .intrMask           */</span>   INTR_MASK,</div><div class="line">        <span class="comment">/* .satIntrMask        */</span>   0u,                             <span class="comment">/* Disable saturation interrupts. */</span></div><div class="line">        <span class="comment">/* .rangeIntrMask      */</span>   0u,                             <span class="comment">/* Disable limit interrupts. */</span></div><div class="line">        <span class="comment">/* .muxSwitch          */</span>   MUX_SWITCH,</div><div class="line">        <span class="comment">/* .muxSwitchSqCtrl    */</span>   MUX_SWITCH_SQ_CTRL,</div><div class="line">        <span class="comment">/* .configRouting      */</span>   <span class="keyword">true</span>,                           <span class="comment">/* Configure the routing. */</span></div><div class="line">        <span class="comment">/* .vrefMvValue        */</span>   1650u,                          <span class="comment">/* Vdda = 3.3 V so Vref = Vdda/2 = 1.65 V. */</span></div><div class="line">        <span class="comment">/* .clock              */</span>   <a class="code" href="group__group__sar__enums.html#ggafb3f29ae5d74207c150af291d3af977eaacc754c080058f48571463d23c6bc73e">CY_SAR_CLK_PERI</a>,</div><div class="line">        <span class="comment">/* .fifoCfgPtr         */</span>   NULL,</div><div class="line">        <span class="comment">/* .trTimer            */</span>   <span class="keyword">false</span>,</div><div class="line">        <span class="comment">/* .scanCnt            */</span>   <span class="keyword">false</span>,</div><div class="line">        <span class="comment">/* .scanCntIntr        */</span>   <span class="keyword">false</span></div><div class="line">    };</div><div class="line">    </div><div class="line">    <a class="code" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a> status;</div><div class="line">    status = <a class="code" href="group__group__sar__functions__basic.html#ga5c053a77ca29519ca29da56da7eaeebe">Cy_SAR_Init</a>(SAR_HW, &amp;config);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> (<a class="code" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a1bcc04151b677cb6e16050b40309b21a">CY_SAR_SUCCESS</a> == status)</div><div class="line">    {</div><div class="line">        <span class="comment">/* Turn on the SAR hardware. */</span></div><div class="line">        <a class="code" href="group__group__sar__functions__basic.html#ga4b8bb939483fac5768910156075d4264">Cy_SAR_Enable</a>(SAR_HW);</div><div class="line"></div><div class="line">        <span class="comment">/* Begin continuous conversions. */</span></div><div class="line">        <a class="code" href="group__group__sar__functions__basic.html#ga92cb7f3c5947df6e47b59f1b2796883c">Cy_SAR_StartConvert</a>(SAR_HW, <a class="code" href="group__group__sar__enums.html#ggaf21d08e4f15f54ac638943e50538d95caf9d6d2d190b4a044611be54dbe147890">CY_SAR_START_CONVERT_CONTINUOUS</a>);</div><div class="line">    }    </div></div><!-- fragment --></dd></dl>

</div>
</div>
<a id="ga65876b1a551f1d189b4abcdb24ff82fa"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga65876b1a551f1d189b4abcdb24ff82fa">&#9670;&nbsp;</a></span>Cy_SAR_DeInit()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a> Cy_SAR_DeInit </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>deInitRouting</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Reset SAR registers back to power on reset defaults. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">deInitRouting</td><td>If true, all SARMUX switches are opened and switch control registers are reset to zero. If false, switch registers are untouched.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><ul>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a1bcc04151b677cb6e16050b40309b21a">CY_SAR_SUCCESS</a> : de-initialization complete</li>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a57b9a5eff2273406f83163b1327d90a3">CY_SAR_BAD_PARAM</a> : input pointers are null, de-initialization incomplete</li>
</ul>
</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: Switch to a different SAR configuration, for example, to scan different channels.</span></div><div class="line"><span class="comment">     * Disable and reset all SAR settings and analog routing before re-initialization. */</span></div><div class="line">    </div><div class="line">    <span class="keywordtype">bool</span> deInitRouting = <span class="keyword">true</span>;</div><div class="line">    (void) <a class="code" href="group__group__sar__functions__basic.html#ga65876b1a551f1d189b4abcdb24ff82fa">Cy_SAR_DeInit</a>(SAR_HW, deInitRouting);</div></div><!-- fragment -->
</div>
</div>
<a id="ga4b8bb939483fac5768910156075d4264"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga4b8bb939483fac5768910156075d4264">&#9670;&nbsp;</a></span>Cy_SAR_Enable()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Cy_SAR_Enable </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Power up the SAR ADC subsystem block. </p>
<p>The hardware is ready to use after 2 us, which is included in this function.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None </dd></dl>

</div>
</div>
<a id="ga09f2185e586c580e622a252580793a25"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga09f2185e586c580e622a252580793a25">&#9670;&nbsp;</a></span>Cy_SAR_Disable()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Cy_SAR_Disable </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Turn off the hardware block. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None </dd></dl>

</div>
</div>
<a id="ga92cb7f3c5947df6e47b59f1b2796883c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga92cb7f3c5947df6e47b59f1b2796883c">&#9670;&nbsp;</a></span>Cy_SAR_StartConvert()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Cy_SAR_StartConvert </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__group__sar__enums.html#gaf21d08e4f15f54ac638943e50538d95c">cy_en_sar_start_convert_sel_t</a>&#160;</td>
          <td class="paramname"><em>startSelect</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Start a single scan (one shot) of all enabled channels or start scanning continuously. </p>
<p>When in continuous mode, all firmware and hardware triggers are ignored. To stop continuous scanning, call <a class="el" href="group__group__sar__functions__basic.html#ga1397031ccf2c1f8a5a95a77f9362e1d1">Cy_SAR_StopConvert</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">startSelect</td><td>A value of the enum <a class="el" href="group__group__sar__enums.html#gaf21d08e4f15f54ac638943e50538d95c">cy_en_sar_start_convert_sel_t</a></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: Initiate scanning in continuous mode. */</span></div><div class="line">    <a class="code" href="group__group__sar__functions__basic.html#ga92cb7f3c5947df6e47b59f1b2796883c">Cy_SAR_StartConvert</a>(SAR_HW, <a class="code" href="group__group__sar__enums.html#ggaf21d08e4f15f54ac638943e50538d95caf9d6d2d190b4a044611be54dbe147890">CY_SAR_START_CONVERT_CONTINUOUS</a>);</div></div><!-- fragment -->
</div>
</div>
<a id="ga1397031ccf2c1f8a5a95a77f9362e1d1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga1397031ccf2c1f8a5a95a77f9362e1d1">&#9670;&nbsp;</a></span>Cy_SAR_StopConvert()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Cy_SAR_StopConvert </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Stop continuous scanning of enabled channels. </p>
<p>If a conversion is currently executing, that conversion will complete, but no further conversions will occur until the next call to <a class="el" href="group__group__sar__functions__basic.html#ga92cb7f3c5947df6e47b59f1b2796883c">Cy_SAR_StartConvert</a> or the next hardware trigger, if enabled.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: Stop continuous scanning so that scans can be firmware triggered (one-shot mode). */</span></div><div class="line">    <a class="code" href="group__group__sar__functions__basic.html#ga1397031ccf2c1f8a5a95a77f9362e1d1">Cy_SAR_StopConvert</a>(SAR_HW);</div></div><!-- fragment -->
</div>
</div>
<a id="ga977c6fb6f81ee39d27eae43c0e45d85c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga977c6fb6f81ee39d27eae43c0e45d85c">&#9670;&nbsp;</a></span>Cy_SAR_IsEndConversion()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a> Cy_SAR_IsEndConversion </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="group__group__sar__enums.html#ga31da850b49ff727a00789aaa33104c59">cy_en_sar_return_mode_t</a>&#160;</td>
          <td class="paramname"><em>retMode</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Immediately return the status of the conversion or does not return (blocking) until the conversion completes, depending on the retMode parameter. </p>
<p>In blocking mode, there is a time out of about 10 seconds for a CPU speed of 100 MHz.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">retMode</td><td>A value of the enum <a class="el" href="group__group__sar__enums.html#ga31da850b49ff727a00789aaa33104c59">cy_en_sar_return_mode_t</a></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><ul>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a1bcc04151b677cb6e16050b40309b21a">CY_SAR_SUCCESS</a> : the last conversion is complete</li>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a2f9bf37990569d42668c00e88de46f45">CY_SAR_CONVERSION_NOT_COMPLETE</a> : the conversion has not completed</li>
<li><a class="el" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a44e1566e197fcff713fcfde3cdac7b7a">CY_SAR_TIMEOUT</a> : the watchdog timer has expired in blocking mode</li>
</ul>
</dd></dl>
<dl class="section user"><dt>Side Effects</dt><dd>This function reads the end of conversion status and clears it after.</dd></dl>
<dl class="section note"><dt>Note</dt><dd><a class="el" href="group__group__sar__enums.html#gga31da850b49ff727a00789aaa33104c59a23c1dd72a6ee1a41e29358eeafe34c0b">CY_SAR_WAIT_FOR_RESULT</a> and <a class="el" href="group__group__sar__enums.html#gga31da850b49ff727a00789aaa33104c59a6f6d8250b0edfc232694f3a76f2badbc">CY_SAR_WAIT_FOR_RESULT_INJ</a> return modes are not recommended for use in RTOS environment.</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: SAR conversions are configured for one-shot firmware triggered mode.</span></div><div class="line"><span class="comment">     * Before triggering the next scan, make sure the current conversion has completed.</span></div><div class="line"><span class="comment">     * Implement a state machine to avoid blocking code. */</span></div><div class="line">    </div><div class="line"><span class="preprocessor">    #define SCAN    (0u)</span></div><div class="line"><span class="preprocessor">    #define PROCESS (1u)</span></div><div class="line">    </div><div class="line">    uint8_t state = SCAN;</div><div class="line">    <a class="code" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a> status;</div><div class="line">    int16_t <a class="code" href="group__group__ipc__bt__data__structures.html#ga36692bbc61358ebc0e37a6fc6a395d28">result</a> = 0;</div><div class="line">    int16_t injResult = 0;</div><div class="line">    </div><div class="line">    <span class="keywordflow">for</span>(;;)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">switch</span>(state)</div><div class="line">        {</div><div class="line">        <span class="keywordflow">case</span> SCAN:</div><div class="line">            <span class="comment">/* Initiate an injection channel sample within the next scan. */</span></div><div class="line">            <a class="code" href="group__group__sar__functions__basic.html#ga397abcd1a595c0846971769a8fe2d564">Cy_SAR_EnableInjection</a>(SAR_HW, <span class="keyword">true</span>);</div><div class="line">            <span class="comment">/* Initiate a single (one shot) scan. */</span></div><div class="line">            <a class="code" href="group__group__sar__functions__basic.html#ga92cb7f3c5947df6e47b59f1b2796883c">Cy_SAR_StartConvert</a>(SAR_HW, <a class="code" href="group__group__sar__enums.html#ggaf21d08e4f15f54ac638943e50538d95ca2aae9e550dc6dd379d8a37d28445dbbf">CY_SAR_START_CONVERT_SINGLE_SHOT</a>);</div><div class="line">            state = PROCESS;</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        <span class="keywordflow">case</span> PROCESS:</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        <span class="keywordflow">default</span>:</div><div class="line">            <span class="comment">/* Query end of conversion status. */</span></div><div class="line">            status = <a class="code" href="group__group__sar__functions__basic.html#ga977c6fb6f81ee39d27eae43c0e45d85c">Cy_SAR_IsEndConversion</a>(SAR_HW, <a class="code" href="group__group__sar__enums.html#gga31da850b49ff727a00789aaa33104c59a9f85f2cc172774017e8ae7699927046e">CY_SAR_RETURN_STATUS</a>);</div><div class="line">            <span class="keywordflow">if</span> (<a class="code" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a1bcc04151b677cb6e16050b40309b21a">CY_SAR_SUCCESS</a> == status)</div><div class="line">            {</div><div class="line">                <span class="comment">/* Retrieve result and do something with it here. */</span></div><div class="line">                result = <a class="code" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a>(SAR_HW, 0);</div><div class="line">                CY_UNUSED_PARAMETER(result); <span class="comment">/* Suppress compiler errors */</span></div><div class="line">                </div><div class="line">                <span class="comment">/* Start next scan. */</span></div><div class="line">                state = SCAN;</div><div class="line">            } <span class="comment">/* else, conversion has not completed. */</span></div><div class="line"></div><div class="line">            <span class="keywordflow">if</span> (<a class="code" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a1bcc04151b677cb6e16050b40309b21a">CY_SAR_SUCCESS</a> == <a class="code" href="group__group__sar__functions__basic.html#ga977c6fb6f81ee39d27eae43c0e45d85c">Cy_SAR_IsEndConversion</a>(SAR_HW, <a class="code" href="group__group__sar__enums.html#gga31da850b49ff727a00789aaa33104c59a57a6bc812cac15b69f11ef6bb75cf25a">CY_SAR_RETURN_STATUS_INJ</a>))</div><div class="line">            {</div><div class="line">                <span class="comment">/* Retrieve result and do something with it here. */</span></div><div class="line">                injResult = <a class="code" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a>(SAR_HW, <a class="code" href="group__group__sar__macros.html#ga92cec01d80f386f95916cc4f0ef238af">CY_SAR_INJ_CHANNEL</a>);</div><div class="line">                CY_UNUSED_PARAMETER(injResult); <span class="comment">/* Suppress compiler errors */</span></div><div class="line">            } <span class="comment">/* else, conversion has not completed. */</span></div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">    }</div><div class="line"></div></div><!-- fragment -->
</div>
</div>
<a id="ga5d7a3489629382b1e46477c034bbb2d0"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5d7a3489629382b1e46477c034bbb2d0">&#9670;&nbsp;</a></span>Cy_SAR_GetResult16()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int16_t Cy_SAR_GetResult16 </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>chan</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Return the data available in the channel result data register as a signed 16-bit integer. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">chan</td><td>The channel to read the result from, between 0 and <a class="el" href="group__group__sar__macros.html#ga92cec01d80f386f95916cc4f0ef238af">CY_SAR_INJ_CHANNEL</a></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Data is returned as a signed 16-bit integer. If channel number is invalid, 0 is returned.</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: ADC conversion has completed and result is valid.</span></div><div class="line"><span class="comment">     * Retrieve the result on channel 0 and convert it to millivolts. */</span></div><div class="line">    uint32_t chan = 0UL;</div><div class="line">    int16_t <a class="code" href="group__group__ipc__bt__data__structures.html#ga36692bbc61358ebc0e37a6fc6a395d28">result</a>;</div><div class="line">    int16_t resultmV;</div><div class="line">    </div><div class="line">    result = <a class="code" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a>(SAR_HW, chan);</div><div class="line">    </div><div class="line">    resultmV = <a class="code" href="group__group__sar__functions__countsto.html#ga8f1189056459a76c4b9f9917dc3a9e6e">Cy_SAR_CountsTo_mVolts</a>(SAR_HW, chan, result);</div></div><!-- fragment -->
</div>
</div>
<a id="gafe907896ffee98cc780042ad77fe71cc"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gafe907896ffee98cc780042ad77fe71cc">&#9670;&nbsp;</a></span>Cy_SAR_GetResult32()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int32_t Cy_SAR_GetResult32 </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>chan</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Return the data available in the channel result data register as a signed 32-bit integer. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">chan</td><td>The channel to read the result from, between 0 and <a class="el" href="group__group__sar__macros.html#ga92cec01d80f386f95916cc4f0ef238af">CY_SAR_INJ_CHANNEL</a></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Data is returned as a signed 32-bit integer. If channel number is invalid, 0 is returned.</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: ADC conversion has completed and result is valid.</span></div><div class="line"><span class="comment">     * Retrieve the result on channel 0 as a signed 32-bit integer. */</span></div><div class="line">    uint32_t chan = 0UL;</div><div class="line">    int32_t <a class="code" href="group__group__ipc__bt__data__structures.html#ga36692bbc61358ebc0e37a6fc6a395d28">result</a>;</div><div class="line">    </div><div class="line">    result = <a class="code" href="group__group__sar__functions__basic.html#gafe907896ffee98cc780042ad77fe71cc">Cy_SAR_GetResult32</a>(SAR_HW, chan);</div></div><!-- fragment -->
</div>
</div>
<a id="ga859687d40491a053c7fd8d489244f2ac"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga859687d40491a053c7fd8d489244f2ac">&#9670;&nbsp;</a></span>Cy_SAR_GetChanResultUpdated()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">__STATIC_INLINE uint32_t Cy_SAR_GetChanResultUpdated </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Return whether the RESULT register has been updated or not. </p>
<p>If the bit is high, the corresponding channel RESULT register was updated, i.e. was sampled during the previous scan and, in case of Interleaved averaging, reached the averaging count. If the bit is low, the corresponding channel is not enabled or the averaging count is not yet reached for Interleaved averaging.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Each bit of the result corresponds to the channel. Bit 0 is for channel 0, etc.</dd></dl>
<dl class="section user"><dt>Function Usage</dt><dd></dd></dl>
<div class="fragment"><div class="line">    <span class="comment">/* Scenario: The averaging mode has been set to interleaved.</span></div><div class="line"><span class="comment">     * In interleaved mode, it is not enough to rely on the EOS interrupt</span></div><div class="line"><span class="comment">     * to determine if the result is valid. One must call Cy_SAR_GetChanResultUpdated() as well. */</span></div><div class="line">    </div><div class="line">    uint32_t chan = 0UL;</div><div class="line">    uint32_t chanMask = (1u &lt;&lt; chan);</div><div class="line">    uint32_t chanResultUpdated;</div><div class="line">    </div><div class="line">    chanResultUpdated = <a class="code" href="group__group__sar__functions__basic.html#ga859687d40491a053c7fd8d489244f2ac">Cy_SAR_GetChanResultUpdated</a>(SAR_HW);</div><div class="line">    <span class="keywordflow">if</span> (chanMask == (chanResultUpdated &amp; chanMask))</div><div class="line">    {</div><div class="line">        <span class="comment">/* Averaging is complete and the result is valid. Retrieve the result and do something here. */</span></div><div class="line">        </div><div class="line">    } <span class="comment">/* else, result is not yet valid. */</span></div><div class="line"></div></div><!-- fragment -->
</div>
</div>
<a id="ga397abcd1a595c0846971769a8fe2d564"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga397abcd1a595c0846971769a8fe2d564">&#9670;&nbsp;</a></span>Cy_SAR_EnableInjection()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">__STATIC_INLINE void Cy_SAR_EnableInjection </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_s_a_r___type.html">SAR_Type</a> *&#160;</td>
          <td class="paramname"><em>base</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&#160;</td>
          <td class="paramname"><em>tailgating</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Triggers the injection channel sample. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">base</td><td>Pointer to structure describing registers</td></tr>
    <tr><td class="paramname">tailgating</td><td>Injection channel tailgating enable:<ul>
<li>true: The addressed pin is sampled after the next trigger and after all enabled channels have been scanned.</li>
<li>false: SAR is immediately triggered when the SAR is not busy. If the SAR is busy, the INJ channel addressed pin is sampled at the end of the current scan.</li>
</ul>
</td></tr>
  </table>
  </dd>
</dl>
<dl class="section user"><dt>Function Usage</dt><dd><div class="fragment"><div class="line">    <span class="comment">/* Scenario: SAR conversions are configured for one-shot firmware triggered mode.</span></div><div class="line"><span class="comment">     * Before triggering the next scan, make sure the current conversion has completed.</span></div><div class="line"><span class="comment">     * Implement a state machine to avoid blocking code. */</span></div><div class="line">    </div><div class="line"><span class="preprocessor">    #define SCAN    (0u)</span></div><div class="line"><span class="preprocessor">    #define PROCESS (1u)</span></div><div class="line">    </div><div class="line">    uint8_t state = SCAN;</div><div class="line">    <a class="code" href="group__group__sar__enums.html#ga4061024a91b0f2e3aca4716fce722b57">cy_en_sar_status_t</a> status;</div><div class="line">    int16_t result = 0;</div><div class="line">    int16_t injResult = 0;</div><div class="line">    </div><div class="line">    <span class="keywordflow">for</span>(;;)</div><div class="line">    {</div><div class="line">        <span class="keywordflow">switch</span>(state)</div><div class="line">        {</div><div class="line">        <span class="keywordflow">case</span> SCAN:</div><div class="line">            <span class="comment">/* Initiate an injection channel sample within the next scan. */</span></div><div class="line">            <a class="code" href="group__group__sar__functions__basic.html#ga397abcd1a595c0846971769a8fe2d564">Cy_SAR_EnableInjection</a>(SAR_HW, <span class="keyword">true</span>);</div><div class="line">            <span class="comment">/* Initiate a single (one shot) scan. */</span></div><div class="line">            <a class="code" href="group__group__sar__functions__basic.html#ga92cb7f3c5947df6e47b59f1b2796883c">Cy_SAR_StartConvert</a>(SAR_HW, <a class="code" href="group__group__sar__enums.html#ggaf21d08e4f15f54ac638943e50538d95ca2aae9e550dc6dd379d8a37d28445dbbf">CY_SAR_START_CONVERT_SINGLE_SHOT</a>);</div><div class="line">            state = PROCESS;</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        <span class="keywordflow">case</span> PROCESS:</div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        <span class="keywordflow">default</span>:</div><div class="line">            <span class="comment">/* Query end of conversion status. */</span></div><div class="line">            status = <a class="code" href="group__group__sar__functions__basic.html#ga977c6fb6f81ee39d27eae43c0e45d85c">Cy_SAR_IsEndConversion</a>(SAR_HW, <a class="code" href="group__group__sar__enums.html#gga31da850b49ff727a00789aaa33104c59a9f85f2cc172774017e8ae7699927046e">CY_SAR_RETURN_STATUS</a>);</div><div class="line">            <span class="keywordflow">if</span> (<a class="code" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a1bcc04151b677cb6e16050b40309b21a">CY_SAR_SUCCESS</a> == status)</div><div class="line">            {</div><div class="line">                <span class="comment">/* Retrieve result and do something with it here. */</span></div><div class="line">                result = <a class="code" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a>(SAR_HW, 0);</div><div class="line">                CY_UNUSED_PARAMETER(result); <span class="comment">/* Suppress compiler errors */</span></div><div class="line">                </div><div class="line">                <span class="comment">/* Start next scan. */</span></div><div class="line">                state = SCAN;</div><div class="line">            } <span class="comment">/* else, conversion has not completed. */</span></div><div class="line"></div><div class="line">            <span class="keywordflow">if</span> (<a class="code" href="group__group__sar__enums.html#gga4061024a91b0f2e3aca4716fce722b57a1bcc04151b677cb6e16050b40309b21a">CY_SAR_SUCCESS</a> == <a class="code" href="group__group__sar__functions__basic.html#ga977c6fb6f81ee39d27eae43c0e45d85c">Cy_SAR_IsEndConversion</a>(SAR_HW, <a class="code" href="group__group__sar__enums.html#gga31da850b49ff727a00789aaa33104c59a57a6bc812cac15b69f11ef6bb75cf25a">CY_SAR_RETURN_STATUS_INJ</a>))</div><div class="line">            {</div><div class="line">                <span class="comment">/* Retrieve result and do something with it here. */</span></div><div class="line">                injResult = <a class="code" href="group__group__sar__functions__basic.html#ga5d7a3489629382b1e46477c034bbb2d0">Cy_SAR_GetResult16</a>(SAR_HW, <a class="code" href="group__group__sar__macros.html#ga92cec01d80f386f95916cc4f0ef238af">CY_SAR_INJ_CHANNEL</a>);</div><div class="line">                CY_UNUSED_PARAMETER(injResult); <span class="comment">/* Suppress compiler errors */</span></div><div class="line">            } <span class="comment">/* else, conversion has not completed. */</span></div><div class="line">            <span class="keywordflow">break</span>;</div><div class="line">        }</div><div class="line">    }</div><div class="line"></div></div><!-- fragment --></dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part
<div id="nav-path" class="navpath">
    <ul>
        <li class="footer">
            Generated for <b>MTB CAT1 Peripheral driver library</b> by <b>Cypress Semiconductor Corporation</b>.
            All rights reserved.
        </li>
    </ul>
</div>
-->
</body>
</html>
